﻿<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
      xmlns:localViewmodel="clr-namespace:Corina.Win.ServerHub.Viewmodels;assembly=Corina.Win.ServerHub">
    <Page.DataContext>
        <localViewmodel:DeviceMeasureViewmodel />
    </Page.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <DataGrid Grid.Row="1"
                  Margin="0,12"
                  AutoGenerateColumns="False"
                  CanUserSortColumns="False"
                  ColumnWidth="*"
                  HeadersVisibility="Column"
                  IsReadOnly="True"
                  ItemsSource="{Binding ItemsCollection}">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="设备">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock VerticalAlignment="Center">
                                <Run Text="{Binding DeviceSn, Mode=OneWay}" />
                                <Run Text="【" />
                                <Run Text="{Binding Kind, Mode=OneWay}" />
                                <Run Text="】" />
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Binding="{Binding Name, Mode=OneWay}" Header="名称" />
                <DataGridTextColumn Width="80"
                                    Binding="{Binding Density,
                                                      Mode=OneWay}"
                                    Header="浓度" />
                <DataGridTextColumn Width="80"
                                    Binding="{Binding Temperature,
                                                      Mode=OneWay}"
                                    Header="温度" />
                <DataGridTextColumn Width="80"
                                    Binding="{Binding Humidity,
                                                      Mode=OneWay}"
                                    Header="湿度" />
                <DataGridTextColumn Width="100"
                                    Binding="{Binding TestTime,
                                                      Mode=OneWay,
                                                      StringFormat=\{0:yyyy-MM-dd HH:mm tt\}}"
                                    Header="时间" />

                <DataGridTemplateColumn Width="80" Header="是否公开">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Button Style="{StaticResource CheckButtonStyle}" Visibility="{Binding IsOpen, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <i:InvokeCommandAction Command="{Binding Path=DataContext.SetHideCommand, RelativeSource={RelativeSource AncestorType=Page}}" CommandParameter="{Binding Id}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>
                                <Button Style="{StaticResource CrossButtonStyle}" Visibility="{Binding IsOpen, Mode=OneWay, Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <i:InvokeCommandAction Command="{Binding Path=DataContext.SetOpenCommand, RelativeSource={RelativeSource AncestorType=Page}}" CommandParameter="{Binding Id}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

            </DataGrid.Columns>
        </DataGrid>

        <StackPanel Grid.Row="2"
                    HorizontalAlignment="Right"
                    Orientation="Horizontal">
            <Button Command="{Binding FirstPageCommand}" Style="{StaticResource FirstPageButtonStyle}" />
            <Button Margin="12,0"
                    Command="{Binding PreviousPageCommand}"
                    Style="{StaticResource PreviousPageButtonStyle}" />
            <TextBlock Margin="12,0" VerticalAlignment="Center">
                <Run Text="{Binding Index, Mode=OneWay}" />
                <Run Text="/" />
                <Run Text="{Binding PagesCount, Mode=OneWay}" />
            </TextBlock>
            <Button Margin="12,0"
                    Command="{Binding NextPageCommand}"
                    Style="{StaticResource NextPageButtonStyle}" />
            <Button Command="{Binding LastPageCommand}" Style="{StaticResource LastPageButtonStyle}" />
        </StackPanel>
    </Grid>
</Page>